package com.neuedu.boot.framework;

/**
 * 项目：      springboot
 * 类名:       Res
 * 创建时间：  2024/3/26 11：17
 * 描述 :
 * 作者 :     张金山
 * QQ :     314649444
 * Site:      https://jshand.gitee.io
 */

/**
 * 通用的返回结果
 */
public class Res<T> {

    private Integer code;  //200 404 403 500
    private String msg;
    private T data;


    public Res() {
    }

    public Res(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


    public static Res ok(){
        Res res = new Res();
        res.setCode(200);
        return  res;
    }

    public static Res ok(Object data){
        Res res = ok();
        res.setData(data);
        return  res;
    }

    public static Res failed(Integer code,String msg){
        Res res = new Res(code, msg, null);
        return  res;
    }

    public static Res failed(String msg){
        return  failed(500,msg);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
